/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simhya.model.flat;
import simhya.simengine.Stoichiometry;
import simhya.model.store.Function;
import simhya.model.transition.*;


/**
 *
 * @author Luca
 */
public class LinearNoiseFlatModel extends FlatModel {
    /*
     * Introduci liste di liste di derivata + elenco di coppie stoich - come funzione. Implementa derivate in funzione
     * E implementa il fatto che derivata zero diventa costante zero e che posso controllarlo.
     */
    
    Function[][] jacobianFunctions;
    Stoichiometry[][] jacobianStoichiometry;
    
    
    
    LinearNoiseFlatModel(String name) {
        super(name);
        this.jacobianFunctions = null;
        this.jacobianStoichiometry = null;
    }
    
    void initializeJacobian() {
        jacobianFunctions = new Function[numberOfContinuouslyApproximableTransitions][this.modelVariables.size()];
        jacobianStoichiometry = new Stoichiometry[numberOfContinuouslyApproximableTransitions][];
        for (int i=0;i<this.numberOfContinuouslyApproximableTransitions;i++) {
            Transition t = this.transitions[this.continuouslyApproximableTransitionID[i]];
            for (int j=0;j<this.modelVariables.size();j++) {
                String x = this.modelVariables.get(j);
                jacobianFunctions[i][j] = t.getRateFunction().differentiate(x);
            }
            AtomicReset[] res = t.getResetList();    
            jacobianStoichiometry[i] = new Stoichiometry[res.length];
            for (int j=0;j<res.length;j++) {
                int k = res[j].getUpdatedVariables().get(0);
                jacobianStoichiometry[i][j] = new Stoichiometry(k,res[j].getConstantIncrement());
            }
        }
    }
    
    
    public Function[][] getJacobianFunctions() {
        return this.jacobianFunctions;
    } 
    
    public Stoichiometry[][] getJacobianStoichiometry() {
        return this.jacobianStoichiometry;
    }

    @Override
    public boolean isLinearNoiseApproximation() {
        return true;
    }
    
    
    
}
